<?php

/**
 * @author thihien
 * @copyright 2011
 */


require_once('includes/general.php');
if(!tep_db_checkDb()) die('khong ket noi dc csdl');
$madanhmuc=$_GET['madanhmuc'];
//$sql='select * from sanpham where madanhmuc='.$madanhmuc;
//$kq=tep_db_query($sql);
/* phan trang */
 $sql='SELECT count(id) as count FROM `tbl_san_pham` where ma_danh_muc='.$madanhmuc;
$kq=tep_db_query($sql);
$item1=tep_db_fetch_array($kq);
//bat dau viet phan trang
$display=15;// so san pham xuat hien tren mot trang
$record=$item1['count'];//tong so san pham
if($record>$display){
    $page=ceil($record/$display);
}
else{
    $page=1;
}
$start=isset($_GET['start']) && (int)$_GET['start']?$_GET['start']:0;
$sql4='select * from tbl_san_pham where ma_danh_muc='.$madanhmuc.' limit '.$start.', '.$display.'';
$kq4=tep_db_query($sql4);
 $content='';
/*ket thuc phan lay tong sp*/
$sql3='select ten_danh_muc from tbl_danh_muc_san_pham where id='.$madanhmuc;
$kq3=tep_db_query($sql3);
$item2=tep_db_fetch_array($kq3);

$content.='
    <div id="content">
    
        <div class="tt_sanpham">
        <div class="tieude" id="tieude_tendanhmuc"><h3>'.$item2['ten_danh_muc'].'</h3></div>';
       if($record!=0){
        while($item=tep_db_fetch_array($kq4)){
            $content.='
             
            <div class="show_sanpham">
                <div class="hinhanh_sp"><a href="?page=sanpham&masp='.$item['id'].'&madanhmucsp='.$item['ma_danh_muc'].'&mode=detail"><img  height="120" width="160" src="admin/upload/'.$item['hinh_anh'].'"/></a></div>
                
                <div class="tieude_sp">
                    <div class="tensp" style="margin-top: 5px;">'.$item['ten_san_pham'].'</div>
                    <div style="margin-top: 5px;">'.$item['noi_san_xuat'].'</div>
                    <div class="gia" style="color: red;" > Giá:'.$item['gia'].'</div>
                    <div style="margin-top: 5px;"><a href="?page=sanpham&masp='.$item['id'].'&madanhmucsp='.$item['ma_danh_muc'].'&mode=detail">Chi Tiết...</a></div>
                </div>
            </div>
                
                ';
                
        }
$content.='<ul class="phantrang">';
             $content.='Trang:';
            if($page>1){
                $next=$start+$display;
                $prev=$start-$display;
                $current=($start/$display)+1;
                //hien thi phan trang prev
               
                if($current!=1){
                   $content.='<li><a href="?madanhmuc='.$madanhmuc.'&start='.$prev.'">Previous</a></li>'; 
                }
                 //hien thi trang
                 for($i=1;$i<=$page;$i++){
                   if($current!=$i){
                        $content.='<li><a href="?madanhmuc='.$madanhmuc.'&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    } 
                    else
                    {
                       $content.='<li class="current"><a href="madanhmuc='.$madanhmuc.'&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    }
                     
                 }
                //hien thi next
                if($current!=$page){
                    $content.='<li><a href="?madanhmuc='.$madanhmuc.'&start='.$next.'">Next</a></li>';  
                }
            }
            else{
                $content.='<li class="current"><a href="?madanhmuc='.$madanhmuc.'&start='.$page.'">'.$page.'</a></li>';  
            }
       $content.=' </ul>';}
        
        else{
            $content.='<div class="tt">Thông tin đang cập nhật....</div>';
        }
   $content.='</div>
    </div> 
';
echo $content;


?>